package com.chookss.home.logContacts;

import android.os.Bundle;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chookss.R;
import com.chookss.Urls;
import com.chookss.base.BaseViewHolderEx;
import com.chookss.base.StaticClass;
import com.chookss.home.entity.ContactEntity;
import com.chookss.tools.GlideUtils;
import com.chookss.tools.MyEvent;
import com.chookss.tools.Utils;
import com.chookss.view.CircleImageView;
import com.johnrambo.ktea.ktExtends.ShareUtils;
import com.lvgroup.hospital.base.BaseAct;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;

import org.greenrobot.eventbus.EventBus;

import java.util.HashMap;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class LogContactsChangeActivity extends BaseAct {


    @BindView(R.id.common_title_txt)
    TextView commonTitleTxt;
    @BindView(R.id.rvView)
    RecyclerView recyclerView;
    @BindView(R.id.srlView)
    SmartRefreshLayout srlView;
    private List<ContactEntity> list;
    private ContactsAdapter adapter;
    private String lpFlag = "";//0禁止1正常
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        setContentView(R.layout.common_srlview_center);
        ButterKnife.bind(this);
    }

    @Override
    public void initData() {
        initState();
        lpFlag = new ShareUtils().getString(this, StaticClass.LP_FLAG, "1");
        //禁止截屏
        if ("0".equals(lpFlag)) {
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE);
        }
        commonTitleTxt.setText("转让");
        list = (List<ContactEntity>) getIntent().getSerializableExtra("dataList");
        srlView.setPadding(0, Utils.dip2px(this, 12), 0, 0);
        recyclerView.setBackgroundColor(getResources().getColor(R.color.white));
        recyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
        adapter = new ContactsAdapter(R.layout.item_contacts, list);
        recyclerView.setAdapter(adapter);
        srlView.setEnableRefresh(false);
        srlView.setEnableLoadMore(false);
    }

    class ContactsAdapter extends BaseQuickAdapter<ContactEntity, BaseViewHolderEx> {

        public ContactsAdapter(int layoutResId, List<ContactEntity> data) {
            super(layoutResId, data);
        }

        @Override
        protected void convert(BaseViewHolderEx helper, ContactEntity entity) {
            //组织
            LinearLayout llCompany = helper.getView(R.id.llCompany);
            //员工
            LinearLayout llEmployees = helper.getView(R.id.llEmployees);
            CircleImageView ivEmployees = helper.getView(R.id.ivEmployees);
            ImageView tvEmployeesPhone = helper.getView(R.id.tvEmployeesPhone);
            TextView tvEmployeesName = helper.getView(R.id.tvEmployeesName);
            TextView tvEmployeesJob = helper.getView(R.id.tvEmployeesJob);
            //员工
            llCompany.setVisibility(View.GONE);
            llEmployees.setVisibility(View.VISIBLE);
            GlideUtils.loadAvatar(LogContactsChangeActivity.this, entity.getHeadPhotoThumbUrl(), ivEmployees);
            tvEmployeesName.setText(entity.getEmployeeName());
            tvEmployeesJob.setText(entity.getPost());
            tvEmployeesPhone.setVisibility(View.INVISIBLE);
            ivEmployees.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (Urls.antiShake.check()) {
                        return;
                    }
                    HashMap<String, String> map = new HashMap<>();
                    map.put("LogChangeManger_code", entity.getEmployeeCode());
                    map.put("LogChangeManger_name", entity.getEmployeeName());
                    EventBus.getDefault().post(map);
                    finish();
                }
            });
            helper.getItemView().setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (Urls.antiShake.check()) {
                        return;
                    }
                    HashMap<String, String> map = new HashMap<>();
                    map.put("LogChangeManger_code", entity.getEmployeeCode());
                    map.put("LogChangeManger_name", entity.getEmployeeName());
                    EventBus.getDefault().post(new MyEvent(map));
                    finish();
                }
            });
        }
    }

    @OnClick(R.id.common_title_back)
    public void onClick() {
        finish();
    }
}
